package com.ljf.tijian.controller;

import com.ljf.tijian.dto.OrdersDto;
import com.ljf.tijian.mapper.OrdersMapper;
import com.ljf.tijian.service.OrdersService;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class MsgController {

    @Autowired
    private AmqpTemplate amqpTemplate;

    @Autowired
    OrdersMapper ordersMapper;

    @RequestMapping("/rabbit")
    public List<OrdersDto> rabbit(){
        System.out.println("into test()..........");

        List<OrdersDto> ordersDtoList = ordersMapper.selectAllOrdersForSmId();

        //假装要给各个粉丝发送邮件
        String[] attEmails=new String[]{"yangmi@qq.com","chenlong@qq.com","zhoujielun@qq.com"};
        for(String email:attEmails){
            amqpTemplate.convertAndSend("email_queue",email+"|亲爱的领导，我查询了所有部门的信息，先予以告知");
            System.out.println("服务器发送消息给"+email);
        }
        System.out.println("发送完毕！");
        return ordersDtoList;
    }
}
